package com.autumn.platform.core.context.response;

import java.io.Serializable;
import java.util.Locale;

import com.autumn.platform.core.context.response.impl.Response;
import com.autumn.platform.core.context.track.Tracker;
import com.autumn.platform.core.exception.CodableException;
import com.autumn.platform.core.exception.Throws;

public interface IResponse extends Serializable {

    /**
     * 表示成功状态码
     */
    public String SUCCESS_CODE = "000000";

    /**
     * 表示成功状态描述
     */
    public String SUCCESS_MESSAGE = "Success";

    /**
     * 返回成功状态
     */
    public static IResponse success() {
        return new Response();
    }

    /**
     * 返回成功状态
     */
    public static <R extends IResponse> R success(Class<R> cls) {
        try {
            R r = cls.newInstance();
            r.setCode(SUCCESS_CODE);
            r.setMessage(SUCCESS_MESSAGE);
            r.setSuccess(true);
            r.setTrackId(Tracker.getCurrentTrackId());
            return r;
        } catch (Exception e) {//实例化类失败
            throw Throws.createException("", cls);
        }
    }

    /**
     * 代码
     * 
     * @return
     */
    public String getCode();

    /**
     * 设置返回代码
     * 
     * @param code
     */
    public void setCode(String code);

    /**
     * 设置异常代码，并设置对应的国际化描述
     * 
     * @param code
     * @param args
     */
    public void setExceptionCode(String code, Object... args);

    /**
     * 设置异常代码，并设置对应的国际化描述
     * 
     * @param code
     * @param locale
     * @param args
     */
    public void setExceptionCode(String code, Locale locale, Object... args);

    /**
     * 描述
     * 
     * @return
     */
    public String getMessage();

    /**
     * 设置描述
     * 
     * @param message
     */
    public void setMessage(String message);

    /**
     * 是否成功
     * 
     * @return
     */
    public boolean isSuccess();

    /**
     * 设置是否成功
     * 
     * @param success
     */
    public void setSuccess(boolean success);

    /**
     * 请求跟踪号
     * 
     * @return
     */
    public String getTrackId();

    /**
     * 设置请求跟踪号
     * 
     * @param trackId
     */
    public void setTrackId(String trackId);

    /**
     * 转换为异常
     * 
     * @return
     */
    public CodableException toException();
}
